<?php


namespace app\api\validate;


use app\common\model\service\Order;
use think\Validate;

class CarersOrder extends Validate
{
    protected $rule = [
        'order_id|订单ID' => 'require|checkOrder',
        'reason|拒绝理由' => 'require',
        'code|验证码' => 'require|checkCode'
    ];

    protected $scene = [
        'refuse' => ['order_id','reason'],
        'receive' => ['order_id'],
        'start' => ['order_id','code']
    ];

    public function checkOrder($value, $rule, $data)
    {
        if (!$order = Order::get($value)) {
            return '订单不存在';
        }

        return true;
    }

    public function checkCode($value, $rule, $data)
    {
        $order = Order::get($data['order_id']);
        if ($value != $order['code']) {
            return '验证码错误';
        }

        return true;
    }
}